package ch.mueller.android.nmeaexample.util.readerFactoryElements;

import java.util.LinkedHashMap;

public class GSVAnalyser extends GPSLineAnalyser {

    public GSVAnalyser(String line) {
        super(line);
    }

    @Override
    public LinkedHashMap<String, String> getResult() {
        LinkedHashMap<String, String> element = new LinkedHashMap<String, String>();
        int i = 0;
        String[] splitts = line.split(",");
        element.put("TYPE", getValue(splitts, i++));
        int numberofMessages = Integer.parseInt(getValue(splitts, i++).trim());
        element.put("Mumber of Messages", numberofMessages + "");
        int messageNumber = Integer.parseInt(getValue(splitts, i++).trim());
        element.put("MessageNumber", messageNumber + "");
        if (messageNumber != numberofMessages) {

            element.put("Satelites in Viev", getValue(splitts, i++));
            for (int j = 0; j < numberofMessages; j++) {
                element.put("Satelite ID" + j, rangeCheck(getValue(splitts, i++), 1, 32));
                element.put("Elevation" + j, rangeCheck(getValue(splitts, i++), 0, 90));
                element.put("Azimuth" + j, rangeCheck(getValue(splitts, i++), 0, 359));
                element.put("SNR" + j, rangeCheck(getValue(splitts, i++), 0, 99));
            }
        }
        element.put(CHECKSUM, calculateCheksum(line));
        
        return element;
    }
}
